#include <bits/stdc++.h>
// 2025/01/19
// tag: sort
// Author: Zhang Muen
using namespace std;

const int32_t MAXN = 500001;

int32_t n, num[MAXN], tmp[MAXN];
uint64_t cnt;

void Merge(const int *aBegin, const int *aEnd, const int *bBegin, const int *bEnd, int *c)
{
    while (aBegin != aEnd && bBegin != bEnd)
    {
        if (*bBegin < *aBegin)
        {
            *c = *bBegin;
            ++bBegin, cnt += aEnd - aBegin;
        }
        else
        {
            *c = *aBegin;
            ++aBegin;
        }
        ++c;
    }
    for (; aBegin != aEnd; ++aBegin, ++c)
        *c = *aBegin;
    for (; bBegin != bEnd; ++bBegin, ++c)
        *c = *bBegin;
}

void merge_sort(int *a, size_t n)
{
    for (size_t seg = 1; seg < n; seg <<= 1)
    {
        for (size_t left1 = 0; left1 < n - seg; left1 += seg + seg)
        { // n - seg: 如果最后只有一个段就不用合并
            size_t right1 = left1 + seg;
            size_t left2 = right1;
            size_t right2 = std::min(left2 + seg, n);                         // <!> 注意最后一个段的边界
            Merge(a + left1, a + right1, a + left2, a + right2, tmp + left1); // pointer-style merge
            for (size_t i = left1; i < right2; ++i)
                a[i] = tmp[i];
        }
    }
}

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> num[i];
    merge_sort(num + 1, n);
    cout << cnt << endl;
    return 0;
}